package com.wanda.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.wanda.model.Opening_PayModel;
import com.wanda.service.Opening_PayService;
import com.wanda.util.DateFormat;

@Controller
@RequestMapping("/ht/opening")
public class Opening_PayController {


	@Autowired
	private Opening_PayService opening_PayService;
	
	//添加支付信息
	@RequestMapping(value="/addOpening.do")
	public @ResponseBody Map<String,Object> add(String pay_type_id,String opening_report_id,String delete_state){
		
		System.out.println("进入添加");
		Opening_PayModel model = new Opening_PayModel();
		model.setPay_type_id(pay_type_id);
		model.setOpening_report_id(opening_report_id);
		model.setDelete_state("0");
		
		opening_PayService.insertOpening(model);
		Map<String,Object> map =new HashMap<String,Object>();
		map.put("msg", "成功");
		return map;
		
	}
	//显示所有
	@RequestMapping(value="/selectAll.do")
	public ModelAndView showAll(){
		
		System.out.println("进入查询");
		
		ModelAndView model = new ModelAndView();
		
		List<Opening_PayModel> list = null;
		try{
			
			list=opening_PayService.selectAll();
			System.err.println("opening_Paycontroller的selectall:"+list);
			model.setViewName("/ht/listOpening_Pay.jsp");
			model.addObject("openinglist",list);
			
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return model;
		
	}
	
	//删除支付
	@RequestMapping(value="/deleteOpening.do")
	public String delete(Opening_PayModel model){
		
		System.out.println("进入删除:"+model);
		model.setOpening_pay_id(model.getOpening_pay_id());
		model.setDelete_time(DateFormat.getNowDate());
		int ids = opening_PayService.deleteOpening(model);
		
		Map<String,Object> map =new HashMap<String,Object>();
		map.put("msg", ids);
		return "redirect:/ht/opening/selectAll.do";
	}
	
	//修改支付
	@RequestMapping(value="/updateOpening.do")
	public String update(Opening_PayModel model){
		
		System.out.println("进入修改");
		model.setUpdate_time(DateFormat.getNowDate());
        opening_PayService.updateOpening(model);
        
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("opening", map);
		return "redirect:/ht/opening/selectAll.do";
	    
}
	//查询某条支付
	@RequestMapping(value="/selectById.do")
	public ModelAndView selectById(String id){
		
		System.out.println("进入单条查询");
		ModelAndView view = new ModelAndView();
		Opening_PayModel model = null;
		try{
			model=opening_PayService.selectById(id);
			view.setViewName("/ht/updateOpening_Pay.jsp");
			view.addObject("opening",model);
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return view;
		
	}
}